from appium import webdriver
import time
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions.mouse_button import MouseButton
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

desired_caps = {
    'platformName':'Android',
    'platformVersion': '7.1.2',
    'deviceName': 'emulator-5554',
    'appPackage': 'com.android.settings',
    'appActivity': '.Settings'
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(1)

# # TouchAction(driver).press(x=500, y=1800).wait(500).move_to(x=500, y=500).release().perform()
# for i in range(3):
#     action = TouchAction(driver).press(x=500, y=1800).wait(200).move_to(x=500, y=500).release()
#     action.perform()
#     time.sleep(2)

driver.start_activity("com.android.gallery3d", ".app.GalleryActivity")
# 进入图库，选择图片，放大
actions = ActionChains(driver)  # 存储动作链
f1 = actions.w3c_actions.add_pointer_input('touch', 'f1')
f1.create_pointer_move(x=520, y=860)
f1.create_pointer_down()
f1.create_pointer_up(MouseButton.LEFT)
actions.perform()

time.sleep(5)

f2 = actions.w3c_actions.add_pointer_input('touch', 'f2')
f1.create_pointer_move(x=520, y=860)
f2.create_pointer_move(x=520, y=860)
f1.create_pointer_down()
f2.create_pointer_down()
f1.create_pointer_move(x=1000, y=300)
f2.create_pointer_move(x=100, y=1700)
f1.create_pointer_up(MouseButton.LEFT)
f2.create_pointer_up(MouseButton.LEFT)
actions.perform()

driver.quit()